#include <stdio.h>
#include "drawingEvent.h"

DrawingEvent::DrawingEvent(const Ice::CommunicatorPtr& c, DrawingEventType d_evt_type) : Event(c)
{
	setMemberValue("type", fromInt(DRAWING_EVENT_TYPE));
	setMemberValue("drawing_event_type", fromInt(d_evt_type));
	setMemberValue("color", fromString("0x000000"));
}

DrawingEvent::~DrawingEvent()
{
	
}

int DrawingEvent::getSubType()
{
	return interpretInt(getMemberValue("drawing_event_type"));
}

std::string DrawingEvent::color()
{	
	return interpretString(getMemberValue("color"));
}

void DrawingEvent::color(const std::string& c)
{
	setMemberValue("color", fromString(c));
}

LineEvent::LineEvent(const Ice::CommunicatorPtr& c, float x0, float y0, float x1, float y1)
 : DrawingEvent(c, LINE)
{
	setMemberValue("x0", fromFloat(x0));
	setMemberValue("y0", fromFloat(y0));
	setMemberValue("x1", fromFloat(x1));
	setMemberValue("y1", fromFloat(y1));
}

float LineEvent::x0()
{
	return interpretFloat(getMemberValue("x0"));
}

float LineEvent::y0()
{
	return interpretFloat(getMemberValue("y0"));
}

float LineEvent::x1()
{
	return interpretFloat(getMemberValue("x1"));
}

float LineEvent::y1()
{
	return interpretFloat(getMemberValue("y1"));
}

RectangleEvent::RectangleEvent(const Ice::CommunicatorPtr& c, float x, float y, float width, float height)
 : DrawingEvent(c, RECTANGLE)
{
	setMemberValue("x", fromFloat(x));
	setMemberValue("y", fromFloat(y));
	setMemberValue("width", fromFloat(width));
	setMemberValue("height", fromFloat(height));
}

float RectangleEvent::x()
{
	return interpretFloat(getMemberValue("x"));
}

float RectangleEvent::y()
{
	return interpretFloat(getMemberValue("y"));
}

float RectangleEvent::width()
{
	return interpretFloat(getMemberValue("width"));
}

float RectangleEvent::height()
{
	return interpretFloat(getMemberValue("height"));
}

FilledRectangleEvent::FilledRectangleEvent(const Ice::CommunicatorPtr& c, float x, float y, float width, float height)
 : RectangleEvent(c, x, y, width, height)
{
	setMemberValue("fill_color", fromString("0xffffff"));
	setMemberValue("drawing_event_type", fromInt(FILLED_RECTANGLE));
}

::std::string FilledRectangleEvent::fillColor()
{
	return interpretString(getMemberValue("fill_color"));
}

void FilledRectangleEvent::fillColor(const ::std::string& c)
{
	setMemberValue("fill_color", fromString(c));
}

EllipseEvent::EllipseEvent(const Ice::CommunicatorPtr& c, float x, float y, float width, float height)
 : DrawingEvent(c, ELLIPSE)
{
	setMemberValue("x", fromFloat(x));
	setMemberValue("y", fromFloat(y));
	setMemberValue("width", fromFloat(width));
	setMemberValue("height", fromFloat(height));
}

float EllipseEvent::x()
{
	return interpretFloat(getMemberValue("x"));
}

float EllipseEvent::y()
{
	return interpretFloat(getMemberValue("y"));
}

float EllipseEvent::width()
{
	return interpretFloat(getMemberValue("width"));
}

float EllipseEvent::height()
{
	return interpretFloat(getMemberValue("height"));
}

FilledEllipseEvent::FilledEllipseEvent(const Ice::CommunicatorPtr& c, float x, float y, float width, float height)
 : EllipseEvent(c, x, y, width, height)
{
	setMemberValue("fill_color", fromString("0xffffff"));
	setMemberValue("drawing_event_type", fromInt(FILLED_ELLIPSE));
}

::std::string FilledEllipseEvent::fillColor()
{
	return interpretString(getMemberValue("fill_color"));
}

void FilledEllipseEvent::fillColor(const ::std::string& c)
{
	setMemberValue("fill_color", fromString(c));
}

CircleEvent::CircleEvent(const Ice::CommunicatorPtr& c, float x, float y, float radius)
 : DrawingEvent(c, CIRCLE)
{
	setMemberValue("x", fromFloat(x));
	setMemberValue("y", fromFloat(y));
	setMemberValue("radius", fromFloat(radius));
}

float CircleEvent::x()
{
	return interpretFloat(getMemberValue("x"));
}

float CircleEvent::y()
{
	return interpretFloat(getMemberValue("y"));
}

float CircleEvent::radius()
{
	return interpretFloat(getMemberValue("radius"));
}

FilledCircleEvent::FilledCircleEvent(const Ice::CommunicatorPtr& c, float x, float y, float radius)
 : CircleEvent(c, x, y, radius)
{
	setMemberValue("fill_color", fromString("0xffffff"));
	setMemberValue("drawing_event_type", fromInt(FILLED_CIRCLE));
}

::std::string FilledCircleEvent::fillColor()
{
	return interpretString(getMemberValue("fill_color"));
}

void FilledCircleEvent::fillColor(const ::std::string& c)
{
	setMemberValue("fill_color", fromString(c));
}

TriangleEvent::TriangleEvent(const Ice::CommunicatorPtr& c, float x0, float y0, float x1, float y1, float x2, float y2)
 : DrawingEvent(c, TRIANGLE)
{
	setMemberValue("x0", fromFloat(x0));
	setMemberValue("y0", fromFloat(y0));
	setMemberValue("x1", fromFloat(x1));
	setMemberValue("y1", fromFloat(y1));
	setMemberValue("x2", fromFloat(x2));
	setMemberValue("y2", fromFloat(y2));
}

float TriangleEvent::x0()
{
	return interpretFloat(getMemberValue("x0"));
}

float TriangleEvent::y0()
{
	return interpretFloat(getMemberValue("y0"));
}

float TriangleEvent::x1()
{
	return interpretFloat(getMemberValue("x1"));
}

float TriangleEvent::y1()
{
	return interpretFloat(getMemberValue("y1"));
}

float TriangleEvent::x2()
{
	return interpretFloat(getMemberValue("x2"));
}

float TriangleEvent::y2()
{
	return interpretFloat(getMemberValue("y2"));
}

FilledTriangleEvent::FilledTriangleEvent(const Ice::CommunicatorPtr& c, float x0, float y0, float x1, float y1, float x2, float y2)
 : TriangleEvent(c, x0,y0,x1,y1,x2,y2)
{
	setMemberValue("fill_color", fromString("0xffffff"));
	setMemberValue("drawing_event_type", fromInt(FILLED_TRIANGLE));
}

::std::string FilledTriangleEvent::fillColor()
{
	return interpretString(getMemberValue("fill_color"));
}

void FilledTriangleEvent::fillColor(const ::std::string& c)
{
	setMemberValue("fill_color", fromString(c));	
}

HandDrawEvent::HandDrawEvent(const Ice::CommunicatorPtr& c, int npoints)
 : DrawingEvent(c, HAND_DRAW)
{
	char x_str[50];
	char y_str[50];
	for (int i=0; i<npoints; i++)
	{
		sprintf(x_str, "x%d", i);
		sprintf(y_str, "y%d", i);
		setMemberValue(x_str, fromFloat(0));
		setMemberValue(y_str, fromFloat(0));
	}
	
	setMemberValue("npoints", fromInt(npoints));
}

int HandDrawEvent::npoints()
{
	return interpretInt(getMemberValue("npoints"));
}

float HandDrawEvent::xn(int n)
{
	char x_str[50];
	sprintf(x_str, "x%d", n);
	
	return interpretFloat(getMemberValue(x_str));
}

float HandDrawEvent::yn(int n)
{
	char y_str[50];
	sprintf(y_str, "y%d", n);
	
	return interpretFloat(getMemberValue(y_str));
}

void HandDrawEvent::xn(int n, float f)
{
	if (n >= 0)
	{
		char str[50];
		sprintf(str, "x%d", n);
		
		setMemberValue(str, fromFloat(f));
	}
}

void HandDrawEvent::yn(int n, float f)
{
	if (n >= 0)
	{
		char str[50];
		sprintf(str, "y%d", n);
		
		setMemberValue(str, fromFloat(f));
	}
}

